package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.db.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage")
public class ManageController {
    @Autowired
    private ManageService manageService;

    @GetMapping("/users")//查询用户列表
    public ResponseEntity users(@RequestParam(defaultValue = "1")Integer page,
                                @RequestParam(defaultValue = "10")Integer pagesize){
        //1.接收分页参数
        //2.调用service处理
        PageResult vo=manageService.users(page,pagesize);
        //3.返回数据
        return ResponseEntity.ok(vo);

    }

    @GetMapping("/users/{userID}")//查询用户的基本资料
    public ResponseEntity users(@PathVariable("userID")Long userID){
        //1.接收参数
        //2.调用service处理业务
        UserInfo userInfo=manageService.findById(userID);
        //3.返回参数
        return ResponseEntity.ok(userInfo);
    }

    @GetMapping("/messages")//查询动态详情列表
    public  ResponseEntity messages(@RequestParam(defaultValue = "1")Integer page,
                                    @RequestParam(defaultValue = "10")Integer pagesize,
                                    Long uid,String state){
        //1.接收参数，分页参数  用户id  动态审核状态码
            //解决前端的bug
        Integer status=null;
        if (!StringUtils.isEmpty(state)&&!"''".equals(state)){
            status=Integer.valueOf(state);
        }
        //2.调用service来处理业务
        PageResult vo=manageService.messages(page,pagesize,uid,status);
        //3.返回参数
        return ResponseEntity.ok(vo);
    }

    @GetMapping("/videos")
    public  ResponseEntity videos (@RequestParam(defaultValue = "1")Integer page,
                                   @RequestParam(defaultValue = "10")Integer pagesize,
                                   Long uid){
        //1.获取请求参数
        //2.调用service处理业务
        PageResult vo=manageService.videos(page,pagesize,uid);
        //3.返回参数
        return ResponseEntity.ok(vo);
    }
}
